<template>
	<view class="coffee-page">
		<z-paging ref="paging" v-model="dataList" @query="queryList">
			<view slot="top">
				<view class="swiper-box" v-if="swiperList.length">
					<u-swiper :list="swiperList" :height="156" keyName="image" :indicator="true" indicatorMode="dot"></u-swiper>
				</view>
				<view class="coffee-info" v-if="coffeeCategory">
					<view class="info-item">
						<image src="../../static/shop/icon_time.png" class="image"></image>
						<view>营业时间：{{coffeeCategory.yy_time}}</view>
					</view>
					<view class="info-item">
						<image src="../../static/shop/icon_phone.png" class="image"></image>
						<view>商家电话：{{coffeeCategory.phone}}</view>
					</view>
				</view>
			</view>
			<view class="coffee-list">
				<view class="coffee-item" v-for="(item,index) in dataList" :key="index">
					<image :src="item.image" class="item-left"></image>
					<view class="item-center">
						<view class="item-title">{{item.name}}</view>
						<view class="item-time">已售:{{item.sales||0}}</view>
						<view class="item-price"><text class="unit">￥</text> {{item.price}}</view>
					</view>
					<view class="item-right">
						<view class="button button1" @click="$Tips('/pages/shop/goodsDetail?goods_id='+item.id)">
							购买
						</view>
					</view>
				</view>
			</view>
		</z-paging>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				dataList: [],
				coffeeCategory: null,
				swiperList: []
			}
		},
		onLoad() {
			this.getIndexData()
			this.getBannerList()
		},
		methods: {
			getBannerList() {
				this.$Api.common.getBannerList({
					type: 5
				}).then(res => {
					this.swiperList = res.data
				})
			},
			getIndexData() {
				this.$Api.common.getIndexData().then(res => {
					this.coffeeCategory = res.data[4]
				})
			},
			queryList(pageNo, pageSize) {
				this.$Api.goods.getGoodsList({
					page: pageNo,
					limit: pageSize,
					label_id: this.coffeeCategory.id
				}).then(res => {
					this.$refs.paging.complete(res.data.data);
				}).catch(res => {
					this.$refs.paging.complete(false);
				})
			}
		}
	}
</script>

<style lang="less" scoped>
	.coffee-page {
		width: 100%;
		min-height: 100vh;
		background: #F6F6F8;

		.coffee-info {
			padding: 16rpx 30rpx;
			background: #ffffff;

			.info-item {
				display: flex;
				align-items: center;
				font-size: 26rpx;
				color: #565656;
				padding: 10rpx 0;

				.image {
					width: 28rpx;
					height: 28rpx;
					margin-right: 8rpx;
				}
			}
		}

		.coffee-list {
			margin-top: 20rpx;
			background-color: #F7F8FA;

			.coffee-item {
				margin: 0 30rpx 20rpx;
				border-radius: 28rpx;
				padding: 20rpx;
				display: flex;
				align-items: center;
				background: #ffffff;
				box-shadow: 0rpx 0rpx 12rpx 0rpx rgba(0, 0, 0, 0.1), inset 0rpx 2rpx 2rpx 0rpx #FFFFFF;

				.item-left {
					width: 156rpx;
					height: 156rpx;
					margin-right: 26rpx;
				}

				.item-center {
					flex: 1;
					height: 156rpx;
					display: flex;
					flex-direction: column;
					justify-content: space-between;

					.item-title {
						font-weight: bold;
						font-size: 32rpx;
					}

					.item-time {
						font-size: 26rpx;
						color: #565656;
						margin-top: 6rpx;
					}

					.item-price {
						font-weight: bold;
						font-size: 40rpx;
						color: #FD463E;
						margin-top: 16rpx;

						.unit {
							font-size: 28rpx;
						}
					}
				}

				.item-right {
					height: 156rpx;
					display: flex;
					flex-direction: column;
					justify-content: flex-end;

					.button {
						width: 112rpx;
						height: 56rpx;
						line-height: 56rpx;
						text-align: center;
						border-radius: 44rpx;
					}

					.button1 {
						color: #ffffff;
						background: linear-gradient(123deg, #E24747 0%, #922020 100%);
						box-shadow: 0rpx 4rpx 12rpx 0rpx rgba(146, 32, 32, 0.3);
					}
				}
			}
		}
	}
</style>